<template>
  <el-dropdown trigger="click" class="international" @command="handleSetLanguage">
    <div>
      <svg-icon class-name="international-icon" icon-class="language"/>
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item in languages" :key="item.key" :disabled="language===item.key" :command="item.key">{{ item.value.text }}</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import { LANGS } from "@/lang";

export default {
  computed: {
    languages() {
      return Object.keys(LANGS).map(key => {
        return { key, value: LANGS[key] };
      });
    },
    language() {
      return this.$store.getters.language;
    }
  },
  methods: {
    handleSetLanguage(lang) {
      this.$store.dispatch("app/setLanguage", lang).then(() => {
        // this.$i18n.locale = LANGS[lang].vue
        location.reload();
      });
    }
  }
};
</script>
